A package that facilitates nice colors created for the Buenrostro Lab. The base of the package including some divergent color schemes were taken from the wesanderson package. This README provides a quick overview of how to use the color schemes with ggplot2 and which palettes are available.
devtools::install_github("caleblareau/BuenColors")
library(BuenColors)
With the library loaded, just type this to get either the continuous or discrete (by default) palette printed in your plot console.
jdb_palette("FantasticFox")
jdb_palette("aqua_brick", type = "continuous")
#> [1] "algae_earth" "aqua_brick" "aqua_tan" "berry"
#> [5] "blue_cyan" "BottleRocket" "BottleRocket2" "brewer_blue"
#> [9] "brewer_celsius" "brewer_fire" "brewer_green" "brewer_heat"
#> [13] "brewer_jamaica" "brewer_marine" "brewer_orange" "brewer_purple"
#> [17] "brewer_red" "brewer_spectra" "brewer_violet" "brewer_yes"
#> [21] "calma_azules" "calma_bosque" "calma_manudo" "calma_marino"
#> [25] "calma_morado" "calma_musgos" "Cavalcanti" "Chevalier"
#> [29] "china_basics" "china_dragon" "china_novice" "china_ranges"
#> [33] "china_sunset" "china_theory" "china_weirdo" "citric"
#> [37] "citric_yellow" "citrus" "cyan_brick" "cyan_green"
#> [41] "cyan_pink" "cyan_purple" "cyan_tan" "cyan_violet"
#> [45] "Darjeeling" "Darjeeling2" "dark_blue" "dark_citrus"
#> [49] "dark_cyan" "dark_violet" "dusk_dawn" "FantasticFox"
#> [53] "flame_artic" "flame_blind" "flame_flame" "flame_light"
#> [57] "flame_macaw" "flame_polar" "flame_volts" "flame_watts"
#> [61] "flame_weird" "flame_wings" "forest" "forest_citric"
#> [65] "forest_yellow" "GrandBudapest" "GrandBudapest2" "horizon"
#> [69] "horizon_extra" "lawhoops" "Moonrise1" "Moonrise2"
#> [73] "Moonrise3" "ocean_aqua" "ocean_brick" "ocean_citrus"
#> [77] "ocean_earth" "ocean_green" "ocean_pink" "ocean_red"
#> [81] "ocean_teal" "purple_baby" "purple_pink" "Royal1"
#> [85] "Royal2" "Rushmore" "samba_color" "samba_light"
#> [89] "samba_night" "solar_basic" "solar_blues" "solar_extra"
#> [93] "solar_flare" "solar_glare" "solar_rojos" "teal_orange"
#> [97] "teal_violet" "white_grove" "white_jungle" "white_mango"
#> [101] "white_orange" "white_tango" "wolfgang_basic" "wolfgang_extra"
#> [105] "Zissou"
To keep consistent color designations, one can use the color_map function to link features to their specific hex color annoations. For example,
jdb_color_map(c("HSC"))
#> [1] "#00441B"
returns the hex code associated with HSC in the Buenrostro Lab paradigm. This function may be applied over multiple features–
jdb_color_map(c("HSC", "CMP", "HSC"))
#> [1] "#00441B" "#FFC179" "#00441B"
and will error out when a feature is not recognized–
jdb_color_map(c("WHAT"))
#> Error: all(name %in% names(jdb_color_maps)) is not TRUE
#> [1] "B" "CD4" "CD8" "CLP" "CMP" "Ery" "GMP" "GMP-A"
#> [9] "GMP-B" "GMP-C" "HSC" "LMPP" "MEP" "mono" "MPP" "NK"
#> [17] "pDC"
To coordinate a ggplot feature (e.g. data point in a scatter plot) with a particular color, this post was a life-saver. Specifically, we’ll use a named vector to coordinate the discrete values. Here’s an example–
xy <- 1:7
cell <- c("GMP-A", "Ery", "CD4", "Ery", "LMPP", "ERY", "MEP")
df <- data.frame(
xy = xy,
cell = cell, stringsAsFactors = FALSE
)
ggplot(df, aes(x = xy, y = xy, color = cell)) +
geom_point(size = 10) + pretty_plot() +
scale_color_manual(values = jdb_color_maps)
#> Warning: Removed 1 rows containing missing values (geom_point).
P.S.– this call will return a blank color for features that are not found in the color map (“ERY” in this example).
The above ggplot command works because jdb_color_maps (with an ‘s’) exists as a named vector in the BuenColors NAMESPACE. The provided function (jdb_color_map) does not have an ‘s’ by the way. This same syntax of supplying a named vector should work for all discrete color scale functionalities in ggplot.
The trick here is to use scale_color_manual like it is shown here–
library(ggplot2)
ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) +
geom_point() + pretty_plot() +
scale_color_manual(values = jdb_palette("brewer_spectra"))
The trick here is to use scale_color_gradientn like it is shown here–
df <- data.frame(x = rnorm(1000), y = 0)
ggplot(df, aes(x=x, y=y, colour=x)) + geom_point() +
scale_color_gradientn(colors = jdb_palette("flame_light")) +
pretty_plot()
Best way that I’ve found to make the density color function represented in the points. Thanks to Kamil Slowikowski for figuring this out.
dat <- data.frame(
x = c(
rnorm(1e4, mean = 0, sd = 0.1),
rnorm(1e3, mean = 0, sd = 0.1)
),
y = c(
rnorm(1e4, mean = 0, sd = 0.1),
rnorm(1e3, mean = 0.1, sd = 0.2)
)
)
dat$density <- get_density(dat$x, dat$y)
ggplot2::ggplot(dat) + geom_point(aes(x, y, color = density)) +
scale_color_gradientn(colors = jdb_palette("solar_extra")) +
pretty_plot()
Quick wrapper using shuf to change the order of plotting points (to a random presentation) to avoid hiding effects.
tdf<-paste(system.file('rds',package='BuenColors'),'basicTSNE.rds',sep='/')
df <- readRDS(tdf)
ggplot(shuf(df)) + geom_point(aes(X1, X2, color = counts)) +
scale_color_gradientn(colors = jdb_palette("solar_extra")) +
pretty_plot()
Here’s what each palette looks like on a continuous scale.
#> $algae_earth
#>
#> $aqua_brick
#>
#> $aqua_tan
#>
#> $berry
#>
#> $blue_cyan
#>
#> $BottleRocket
#>
#> $BottleRocket2
#>
#> $brewer_blue
#>
#> $brewer_celsius
#>
#> $brewer_fire
#>
#> $brewer_green
#>
#> $brewer_heat
#>
#> $brewer_jamaica
#>
#> $brewer_marine
#>
#> $brewer_orange
#>
#> $brewer_purple
#>
#> $brewer_red
#>
#> $brewer_spectra
#>
#> $brewer_violet
#>
#> $brewer_yes
#>
#> $calma_azules
#>
#> $calma_bosque
#>
#> $calma_manudo
#>
#> $calma_marino
#>
#> $calma_morado
#>
#> $calma_musgos
#>
#> $Cavalcanti
#>
#> $Chevalier
#>
#> $china_basics
#>
#> $china_dragon
#>
#> $china_novice
#>
#> $china_ranges
#>
#> $china_sunset
#>
#> $china_theory
#>
#> $china_weirdo
#>
#> $citric
#>
#> $citric_yellow
#>
#> $citrus
#>
#> $cyan_brick
#>
#> $cyan_green
#>
#> $cyan_pink
#>
#> $cyan_purple
#>
#> $cyan_tan
#>
#> $cyan_violet
#>
#> $Darjeeling
#>
#> $Darjeeling2
#>
#> $dark_blue
#>
#> $dark_citrus
#>
#> $dark_cyan
#>
#> $dark_violet
#>
#> $dusk_dawn
#>
#> $FantasticFox
#>
#> $flame_artic
#>
#> $flame_blind
#>
#> $flame_flame
#>
#> $flame_light
#>
#> $flame_macaw
#>
#> $flame_polar
#>
#> $flame_volts
#>
#> $flame_watts
#>
#> $flame_weird
#>
#> $flame_wings
#>
#> $forest
#>
#> $forest_citric
#>
#> $forest_yellow
#>
#> $GrandBudapest
#>
#> $GrandBudapest2
#>
#> $horizon
#>
#> $horizon_extra
#>
#> $lawhoops
#>
#> $Moonrise1
#>
#> $Moonrise2
#>
#> $Moonrise3
#>
#> $ocean_aqua
#>
#> $ocean_brick
#>
#> $ocean_citrus
#>
#> $ocean_earth
#>
#> $ocean_green
#>
#> $ocean_pink
#>
#> $ocean_red
#>
#> $ocean_teal
#>
#> $purple_baby
#>
#> $purple_pink
#>
#> $Royal1
#>
#> $Royal2
#>
#> $Rushmore
#>
#> $samba_color
#>
#> $samba_light
#>
#> $samba_night
#>
#> $solar_basic
#>
#> $solar_blues
#>
#> $solar_extra
#>
#> $solar_flare
#>
#> $solar_glare
#>
#> $solar_rojos
#>
#> $teal_orange
#>
#> $teal_violet
#>
#> $white_grove
#>
#> $white_jungle
#>
#> $white_mango
#>
#> $white_orange
#>
#> $white_tango
#>
#> $wolfgang_basic
#>
#> $wolfgang_extra
#>
#> $Zissou
Here are the discrete color units that go into each scale. If n is small and discrete, note that the colors that are selected are read from left to right.
#> $algae_earth
#>
#> $aqua_brick
#>
#> $aqua_tan
#>
#> $berry
#>
#> $blue_cyan
#>
#> $BottleRocket
#>
#> $BottleRocket2
#>
#> $brewer_blue
#>
#> $brewer_celsius
#>
#> $brewer_fire
#>
#> $brewer_green
#>
#> $brewer_heat
#>
#> $brewer_jamaica
#>
#> $brewer_marine
#>
#> $brewer_orange
#>
#> $brewer_purple
#>
#> $brewer_red
#>
#> $brewer_spectra
#>
#> $brewer_violet
#>
#> $brewer_yes
#>
#> $calma_azules
#>
#> $calma_bosque
#>
#> $calma_manudo
#>
#> $calma_marino
#>
#> $calma_morado
#>
#> $calma_musgos
#>
#> $Cavalcanti
#>
#> $Chevalier
#>
#> $china_basics
#>
#> $china_dragon
#>
#> $china_novice
#>
#> $china_ranges
#>
#> $china_sunset
#>
#> $china_theory
#>
#> $china_weirdo
#>
#> $citric
#>
#> $citric_yellow
#>
#> $citrus
#>
#> $cyan_brick
#>
#> $cyan_green
#>
#> $cyan_pink
#>
#> $cyan_purple
#>
#> $cyan_tan
#>
#> $cyan_violet
#>
#> $Darjeeling
#>
#> $Darjeeling2
#>
#> $dark_blue
#>
#> $dark_citrus
#>
#> $dark_cyan
#>
#> $dark_violet
#>
#> $dusk_dawn
#>
#> $FantasticFox
#>
#> $flame_artic
#>
#> $flame_blind
#>
#> $flame_flame
#>
#> $flame_light
#>
#> $flame_macaw
#>
#> $flame_polar
#>
#> $flame_volts
#>
#> $flame_watts
#>
#> $flame_weird
#>
#> $flame_wings
#>
#> $forest
#>
#> $forest_citric
#>
#> $forest_yellow
#>
#> $GrandBudapest
#>
#> $GrandBudapest2
#>
#> $horizon
#>
#> $horizon_extra
#>
#> $lawhoops
#>
#> $Moonrise1
#>
#> $Moonrise2
#>
#> $Moonrise3
#>
#> $ocean_aqua
#>
#> $ocean_brick
#>
#> $ocean_citrus
#>
#> $ocean_earth
#>
#> $ocean_green
#>
#> $ocean_pink
#>
#> $ocean_red
#>
#> $ocean_teal
#>
#> $purple_baby
#>
#> $purple_pink
#>
#> $Royal1
#>
#> $Royal2
#>
#> $Rushmore
#>
#> $samba_color
#>
#> $samba_light
#>
#> $samba_night
#>
#> $solar_basic
#>
#> $solar_blues
#>
#> $solar_extra
#>
#> $solar_flare
#>
#> $solar_glare
#>
#> $solar_rojos
#>
#> $teal_orange
#>
#> $teal_violet
#>
#> $white_grove
#>
#> $white_jungle
#>
#> $white_mango
#>
#> $white_orange
#>
#> $white_tango
#>
#> $wolfgang_basic
#>
#> $wolfgang_extra
#>
#> $Zissou